package com.shop.web.order;

import java.util.List;

import com.shop.order.domain.ShopCarComm;
import com.shop.order.service.IShopCarCommService;
import com.vip.common.annotation.Log;
import com.vip.common.core.controller.BaseController;
import com.vip.common.core.domain.AjaxResult;
import com.vip.common.core.page.TableDataInfo;
import com.vip.common.enums.BusinessType;
import com.vip.common.utils.poi.ExcelUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 购物车，商品Controller
 * 
 * @author
 */
@Api(tags={" 购物车，商品"})
@RestController
@RequestMapping("/system/commcar")
public class ShopCarCommController extends BaseController
{
    @Autowired
    private IShopCarCommService shopCarCommService;

    /**
     * 查询购物车，商品列表
     */
    @ApiOperation(value = "查询购物车，商品列表")
    @GetMapping("/list")
    public TableDataInfo list(ShopCarComm shopCarComm)
    {
        startPage();
        List<ShopCarComm> list = shopCarCommService.selectShopCarCommList(shopCarComm);
        return getDataTable(list);
    }

    /**
     * 导出购物车，商品列表
     */
    @ApiOperation(value = "导出购物车，商品列表")
    @Log(title = "购物车，商品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ShopCarComm shopCarComm)
    {
        List<ShopCarComm> list = shopCarCommService.selectShopCarCommList(shopCarComm);
        ExcelUtil<ShopCarComm> util = new ExcelUtil<ShopCarComm>(ShopCarComm.class);
        return util.exportExcel(list, "购物车，商品数据");
    }

    /**
     * 获取购物车，商品详细信息
     */
    @ApiOperation(value = "获取购物车，商品详细信息")
    @GetMapping(value = "/{carId}")
    public AjaxResult getInfo(@PathVariable("carId") Long carId)
    {
        return AjaxResult.success(shopCarCommService.selectShopCarCommByCarId(carId));
    }

    /**
     * 新增购物车，商品
     */
    @ApiOperation(value = "新增购物车，商品")
    @Log(title = "购物车，商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopCarComm shopCarComm)
    {
        return toAjax(shopCarCommService.insertShopCarComm(shopCarComm));
    }

    /**
     * 修改购物车，商品
     */
    @ApiOperation(value = "修改购物车，商品")
    @Log(title = "购物车，商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopCarComm shopCarComm)
    {
        return toAjax(shopCarCommService.updateShopCarComm(shopCarComm));
    }

    /**
     * 删除购物车，商品
     */
    @ApiOperation(value = "删除购物车，商品")
    @Log(title = "购物车，商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{carIds}")
    public AjaxResult remove(@PathVariable Long[] carIds)
    {
        return toAjax(shopCarCommService.deleteShopCarCommByCarIds(carIds));
    }
}
